package com.njxxted.activiti.modules.process.task.handler;

import com.njxxted.activiti.common.annotation.StrategyHandleType;
import com.njxxted.activiti.common.constant.Constant;
import com.njxxted.activiti.modules.process.cmd.TaskHandleCmd;
import org.activiti.engine.RuntimeService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 描述：任务激活处理器（策略模式）
 * <p>
 * 作者：Ostrich Hu
 * 时间：2019/9/29 14:00 星期日
 */
@Component
@StrategyHandleType(Constant.Flow.TASK_ACTIVE)
public class ActTaskActiveHandler extends AbstractTaskStrategyHandler {

    @Resource
    private RuntimeService runtimeService;

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public void taskHandle(TaskHandleCmd taskCmd) {
        Map<String, Object> elMap = taskCmd.getVariables();
        logger.debug("审批传递的流程变量：{}", elMap);
        runtimeService.activateProcessInstanceById(taskCmd.getInstanceId());
        setExtendActEntity(Constant.Flow.TASK_ACTIVE, taskCmd, null, null, null, null);
    }
}
